import UIKit

/**
    B站：https://www.bilibili.com/video/BV144411C7Gg?p=8

    第8课内容
    
        1 区间运算符
        2 for in 循环
        3 continue 和 break
*/

let a = 1...4
print(a)

print("范围: \(a)")

let b = 1..<4
let c = -3..<4
let d = (2.5)..<4
let e = (2.5)...4
let f = 0...  // 0~无穷

for index in f {
    print("i=", index)
    if (index > 12) {
        break
    }
}

print("-------------------")

for index in 1...5 {
    print("--- i=", index)
}

print("-------------------")

for index in (1...5).reversed() {
    print("222--- i=", index)
}

print("-------------------")

//-------------------------------------------------------------

for index in stride(from: 0, to: 10, by: 2) { // 不包含结尾的
    print("stride=>", index)
}

print("-------------------")

for index in stride(from: 0, through: 10, by: 2) { // 包含结尾的
    print("stride 包含结尾的 10 =>", index)
}

print("-------------------")

for index in stride(from: 0, to: 10, by: 2).reversed() { // 反向
    print("stride=>", index)
}

print("-------------------")

//-------------------------------------------------------------

for index in (1...5) {
    if (index == 2) {
        break // 可切换方便 被注释掉了
//        continue // 可切换方便 被注释掉了
    }
    print("break/continue=>", index)
}
